package com.itheima.d05_io_buffer_char;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class Test2 {
    public static void main(String[] args) {
        try (FileReader fr = new FileReader("D:\\javabase_ws\\javaAdvanceProject\\day11_io\\src\\com\\itheima\\d05_io_buffer_char\\haiyan.txt");
             FileWriter fw = new FileWriter("D:\\javabase_ws\\javaAdvanceProject\\day11_io\\src\\com\\itheima\\d05_io_buffer_char\\hai.txt");
        BufferedReader bf=new BufferedReader(fr) ;
        BufferedWriter bw = new BufferedWriter(fw);){

            String line;
            ArrayList<String> list = new ArrayList<>();
            while ((line = bf.readLine()) != null) {
                list.add(line);
            }
            list.forEach(System.out::println);
            Collections.sort(list, (s1, s2) -> s2.compareTo(s1));
            for (String s : list) {
                bw.write(s);
                bw.newLine();
            }
        } catch(Exception e){
            e.printStackTrace();
        }
    }
}
